package geno.app;

import java.awt.Dimension;
import java.awt.Rectangle;

public class MyRectangle extends MyShape {

	private Rectangle rect = null;
	private int height;
	private int width;
	
	public MyRectangle() {
		super();
		this.height = 0;
		this.width = 0;
		this.rect = new Rectangle();
	}
	
	// accept only positive values then throw exception
	public MyRectangle(int height, int width) {
		super();
		
		this.height = height;
		this.width = width;
		this.rect = new Rectangle(width, height);
	}
	
	public MyRectangle(String height, String width) {
		if (checkInputs(height, width)) {
			this.height = Integer.parseInt(height);
			this.width = Integer.parseInt(width);
		}
	}
	
	/**
	 * Checks for the validity of the value parameter.
	 * 
	 * @param value Should only be positive number.
	 * @return True if 'value' is positive. Otherwise, false.
	 * @throws NumberFormatException
	 */
	protected boolean checkInputs(String height, String width) {
		
		int heightnum = Integer.parseInt(height);
		int widthnum = Integer.parseInt(width);
		
		if ( heightnum < 0 || widthnum < 0 ) {
			return false;
		}
		
		return true;
	}
			
	public void draw() {
		System.out.println("Actual class Drawing image.");
		render(this.getClass());
	}
	
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}
	
	public int getArea() {
		return height*width;
	}
	
	public String toString() {
		return "Rectangle: height=" + getHeight() + "; width=" + getWidth() + "; area=" + getArea() + ".";
	}
	
	// return true if points x and y are inside the rectangle 
	public boolean contains(int x, int y) {
		if ( rect.contains(x, y) )
			return true;
		return false;
	}
	
	public Dimension getDimension() {
		return new Dimension(this.width, this.height);
	}
	
	public static void staticFunction() {
	}
}
